<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button icon="el-icon-plus" type="primary" @click="open_dialog" />
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model.trim="param.searchkey" clearable placeholder="关键字" />
					<el-button icon="el-icon-search" type="primary" @click="search" />
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable
				ref="table"
				:api-obj="apiObj"
				:column="column"
				row-key="id"
				hideContextMenu>
				<!-- 固定列-选择列 -->
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column align="center" fixed="right" label="操作" width="140">
					<template #default="scope">
						<el-button text type="primary" size="small" @click="open_dialog(scope.row)">编辑</el-button>
						<el-divider direction="vertical" />
						<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
							<template #reference>
								<el-button text type="primary" size="small">删除</el-button>
							</template>
						</el-popconfirm>
					</template>
				</el-table-column>

				<template #isDisabled="{ data }">
					<el-tag disable-transitions :type="data.isDisabled ? 'danger' : 'success'">
						{{ data.isDisabled ? "禁用" : "启用" }}
					</el-tag>
				</template>
			</scTable>
		</el-main>

		<modify ref="modify" @complete="complete" />
	</el-container>
</template>

<script>
import modify from "./modify";

export default {
	components: {
		modify,
	},
	data() {
		return {
			apiObj: this.$API.procprocess.page,
			list: [],
			param: {
				searchkey: "",
			},
			column: [
				{ prop: "id", label: "id", width: 100, hide: true },
				{ prop: 'procCode', label: '工序编号', width: 100 },
				{ prop: 'procName', label: '工序名称', width: 100 },
				{ prop: 'lineCode', label: '产线编号', width: 100 },
				{ prop: 'opCodes', label: '工位集合', width: 160 },
				{ prop: 'classifyDesc', label: '工艺分类', width: 100 },
				{ prop: 'procTypeName', label: '工艺类型', width: 100 },
				{ prop: 'isDisabled', label: '是否禁用', width: 100 },
				{ prop: 'createTime', label: '创建时间', width: 120 },
			],
		};
	},
	methods: {
		complete() {
			this.$refs.table.refresh();
		},
		search() {
			this.$refs.table.upData(this.param);
		},
		async table_del(row) {
			let resp = await this.$API.procprocess.delete.delete([row.id]);
			if (resp.code == 200) {
				this.$refs.table.refresh();
				this.$message.success("删除成功");
			} else {
				this.$alert(resp.message, "提示", { type: "error" });
			}
		},
		open_dialog(row) {
			if (row.id) {
				this.$refs.modify.open(row);
			} else {
				this.$refs.modify.open();
			}
		},
	},
};
</script>
